function queryString(name) {
  var search = location.search.replace('?', '');  // 获取参数字符串
  search = search.split('&');   // ['aaa=dsasa', 'sasaaasaaa=dadad']
  // [['aaa', 'dsasa'], ['aasasda', 'sdsasa']]
  // [{key: 'aaa', value: 'dsasa'}, {}]
  // console.log(search);
  search = search.map((value) => ({
    key: value.split('=')[0],
    value: value.split('=')[1]
  })
  );
  // console.log(search);
  var data = search.filter(({ key }) => key === name)[0];
  // if (data) {
  //   // console.log(data.value);
  //   return data.value;
  // }
  return data ? data.value : '';
}

// function ajax(url, fn) {
//   var xhr = new XMLHttpRequest();
//   xhr.open('get', url);
//   xhr.onreadystatechange = function () {
//     if (xhr.readyState == 4 && xhr.status == 200) {
//       fn(xhr.responseText);
//     }
//   }

//   xhr.send();
// }

// ajax('http://localhost/05list.php', function(data) {
//   console.log(data);
// });

// var options = {
//   successCB: () => { },
//   path: 'dadasdas',
//   params: {},
// }

function ajax(options) {

  var { path, successCB, params = {}, beforeCB = null, type = 'get' } = options;

  var data = '';

  for (var key in params) {
    data += `${key}=${params[key]}&`
  }

  data = data.substring(0, data.length - 1);

  // console.log(data);

  var xhr = new XMLHttpRequest();
  if (type.toLowerCase() === 'get') {
    xhr.open(type, `${path}?${data}`);
    xhr.send();
  } else {
    xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
    xhr.open(type, path);
    xhr.send(data);
  }
  xhr.onreadystatechange = function () {
    if (xhr.readyState == 4 && xhr.status == 200) {
      var data = xhr.responseText;
      try {
        data = JSON.parse(data);
      } catch (e) { }
      // console.log(data);
      successCB && successCB(data);
      // if(successCB) successCB(xhr.responseText)
    } else {
      beforeCB && beforeCB();
    }
  }
}

// ajax('http://localhost/05list.php', function (data) {
//   console.log(data);
//   // data = JSON.parse(data);
// }, {
//   username: '123',
//   age: 18
// });


// 'username=123&age=18'






// var arr = [{ name: 1 }, { name: 2 }];

// var temp = arr.filter(({name}) => name < 1);

// console.log(temp);


// var xhr = new XMLHttpRequest();
// xhr.open('post', 'http://localhost/06delete.php');
// xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
// xhr.onreadystatechange = function() {
//   if(xhr.readyState == 4 && xhr.status == 200) {
//     console.log(xhr.responseText);
//   }
// }

// xhr.send('uid=4&username=32q321');


// 写入cookie
function setCookie(name, content, iDay) {
  var date = new Date();

  var day = date.getDate();
  var hours = date.getHours();

  date.setHours(hours - 8);

  date.setDate(day + iDay);

  document.cookie = `${name}=${content};path=/;expires=` + date;
}
// 删除cookie
function removeCookie(name) {
  setCookie(name, '', -1)
}
// 查找cookie列表
function getCookies() {
  return document.cookie.split('; ').map(item => ({
    name: item.split('=')[0],
    content: item.split('=')[1]
  }));
}

// 查找指定的cookie
function getCookie(key) {
  var list = getCookies();
  var data = list.filter(({ name }) => name === key)[0];
  return data ? data.content : ''
}



// var arr = [1,2,3];

// arr = arr.map(item => item * 1.3)

function jsonp (url){
  
var o = document.querySelector('#ooo')
if(o)o.remove()
var o = document.createElement('script')
o.id = "ooo"

o.src = url
document.body.appendChild(o)
}